//
//  MSWelcomeView.swift
//  SwiftWeibo
//
//  Created by 824810056 on 16/8/16.
//  Copyright © 2016年 DoNews. All rights reserved.
//

import UIKit

class MSWelcomeView: UIView {

    @IBOutlet weak var avatorView: UIImageView!
    
    @IBOutlet weak var welcomeLabel: UILabel!
    
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    class func welcomeView() -> MSWelcomeView {
        
        let nib = UINib(nibName: "MSWelcomeView", bundle: nil)
        
        let view = nib.instantiate(withOwner: nil, options: nil)[0] as! MSWelcomeView
        
        view.frame = UIScreen.main.bounds
        
        return view
    }
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        
        self.layoutIfNeeded()
        
        self.bottomConstraint.constant = self.bounds.height - 200

        UIView.animate(withDuration: 1.5,
                       delay: 0,
                       usingSpringWithDamping: 0.7,
                       initialSpringVelocity: 0,
                       options: [],
                       animations: {
                       
                       self.layoutIfNeeded()
                        
        }){ (_) in
            UIView.animate(withDuration: 0.5, animations: { 
                self.welcomeLabel.alpha = 1
                
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
                    self.removeFromSuperview()
                })
            })
            
        }
    }

}
